package xipujewel.xipujewel.pojo.authority;

import java.util.List;
import java.util.Map;
import java.util.Set;

import net.esoar.modules.utils.Collections3;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
 * 访问资源控制
 * 
 * @author qizai
 * 
 */
public enum Permission {
	// 系统设置
	USER_VIEW(WebViews.R_USER_VIEW, "查看用户", "系统管理"), USER_EDIT(WebViews.R_USER_EDIT, "操作用户", "系统管理"),
	//
	ROLE_VIEW(WebViews.R_ROLE_VIEW, "查看角色", "系统管理"), ROLE_EDIT(WebViews.R_ROLE_EDIT, "操作角色", "系统管理"),
	//
	DEPARTMENT_VIEW(WebViews.R_DEPARTMENT_VIEW, "查看部门", "系统管理"), DEPARTMENT_EDIT(WebViews.R_DEPARTMENT_EDIT, "操作部门", "系统管理"),
	//
	OFFICE_VIEW(WebViews.R_OFFICE_VIEW, "查看科室", "系统管理"), OFFICE_EDIT(WebViews.R_OFFICE_EDIT, "操作科室", "系统管理"),
	//
	JOBPOSITION_VIEW(WebViews.R_JOBPOSITION_VIEW, "查看岗位", "系统管理"), JOBPOSITION_EDIT(WebViews.R_JOBPOSITION_EDIT, "操作岗位", "系统管理"),
	//
	;

	public String value;
	public String displayName;
	public String type;
	private static Map<String, Permission> valueMap = Maps.newHashMap();
	private static Map<String, List<Permission>> listMap = Maps.newHashMap();

	static {
		for (Permission permission : Permission.values()) {
			valueMap.put(permission.value, permission);
			List<Permission> permissionList = listMap.get(permission.type);
			if (permissionList == null) {
				permissionList = Lists.newArrayList();
			}
			permissionList.add(permission);
			listMap.put(permission.type, permissionList);
		}
	}

	Permission(String value, String displayName, String type) {
		this.value = value;
		this.displayName = displayName;
		this.type = type;
	}

	public static String getAllPermission() {
		Set<String> sets = valueMap.keySet();
		return Collections3.convertToString(sets, ",");
	}

	public static Permission parse(String value) {
		return valueMap.get(value);
	}

	public static List<Permission> parseList(String type) {
		return listMap.get(type);
	}

	/**
	 * 按照分类拿去所有的Permission
	 * 
	 * @return
	 */
	public static Map<String, List<Permission>> getListMap() {
		return listMap;
	}

	/**
	 * 按照value拿去所有的Permission
	 * 
	 * @return
	 */
	public static Map<String, Permission> getValueMap() {
		return valueMap;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

}
